package org.cwnuit.course.dao;

import java.sql.SQLException;
import java.util.List;

import org.cwnuit.course.domain.Classgroup;
import org.cwnuit.course.util.IbatisSqlConfig;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 教研室管理DAO
 * @author john
 */
public class ClassgroupDAO{
	
	/**
	 * 根据教研室ID获取教研室信息
	 * @param groupid
	 * @return
	 */
	public Classgroup getClassgroup(Integer groupid) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		Classgroup classgroup = null;
		try {
			classgroup = (Classgroup) sqlMap.queryForObject("Classgroup.getClassgroup",groupid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return classgroup;
	}

	/**
	 * 获取全部教研室信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Classgroup> listClassgroup() {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		List<Classgroup> ClassgroupList = null;
		try {
			ClassgroupList = (List<Classgroup>) sqlMap.queryForList("Classgroup.listClassgroup");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return ClassgroupList;
	}
	
	/**
	 * 添加教研室信息
	 * @param Classgroup
	 * @return
	 */
	public boolean insertClassgroup(Classgroup classgroup) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.insert("Classgroup.insertClassgroup", classgroup);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 更新教研室信息
	 * @param Classgroup* @return
	 */
	public boolean updateClassgroup(Classgroup classgroup) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.update("Classgroup.updateClassgroup",classgroup);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 删除教研室信息
	 * @param groupid
	 * @return
	 */
	public boolean deleteClassgroup(Classgroup classgroup) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.delete("Classgroup.deleteClassgroup", classgroup);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
}
